package com.dtguai.app.api.es;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.time.LocalDateTime;

/**
 * 描述
 *
 * @author guo
 * @date 2020/6/29 16:12
 */
@SpringBootTest
@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
class EsTestTemplate {


    /*@Autowired
    private ElasticsearchRestTemplate template;*/


    @Test
    void esTemplate() {
        //template.indexOps(User.class);
        // ESRestTemplate.indexOps(Article.class).delete();即可

    }
}

@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@Document(indexName = "cx-es-sb-1", shards = 5, replicas = 2)
class UserTemp {

    @Id
    @Field(type = FieldType.Integer, index = false, store = true)
    private int id;

    //@Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_max_word")
    @Field(type = FieldType.Text, analyzer = "ik_smart", searchAnalyzer = "ik_smart")
    private String name;

    @Field(type = FieldType.Integer)
    private int age;

    //pattern = "dd.MM.yyyy hh:mm"
    @Field(type = FieldType.Date, format = DateFormat.date_optional_time, store = true)
    private LocalDateTime createTime;

    @Override
    public String toString() {

        return "id:" + id + ",name:" + name + ",age:" + age + ",createTime:" + createTime;
    }

}
